package unit5.part13;

public class StrategyManager {
    static PayStrategy[] array = {new DecreasePayStrategy(), new DiscountPayStrategy()};

    static PayStrategy select(int type) {
        for (PayStrategy payStrategy : array) {
            if (payStrategy.type() == type) {
                return payStrategy;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(select(0).payAmount(100));
        System.out.println(select(1).payAmount(100));
    }
}

interface PayStrategy {// 优惠策略
    int payAmount(int value);
    int type();
}

class DecreasePayStrategy implements PayStrategy {// 直减
    public int payAmount(int value) {
        return value - 10;
    }
    public int type() {
        return 0;
    }
}

class DiscountPayStrategy implements PayStrategy {// 折半
    public int payAmount(int value) {
        return value / 2;
    }
    public int type() {
        return 1;
    }
}